#include <cstdio>
#include <set>
#include <algorithm>
#include <vector>

using namespace std;

struct Node
{
    int t, h;
};

multiset<int> s;
vector<int> li[ 601 ];
int n, m, a[ 51 ];

void init( )
{
    int i, t, h;
    for ( i = 0; i < n; i++ )
        scanf("%d", &a[ i ]);
    for ( i = 0; i <= 100; i++ ) li[ i ].clear( );
    for ( i = 0; i < m; i++ )
    {
        scanf("%d%d", &t, &h);
        li[ t ].push_back( h );
    }
    sort( a, a + n );
    s.clear( );
}

void work( )
{
    multiset<int>::iterator ii;
    int i, j, ans = 0;
    for ( i = 1; i <= 600; i++ )
    {
        for ( j = 0; j < li[ i ].size( ); j++ )
            s.insert( li[ i ][ j ] + i );
        for ( j = 0; j < n; j++ )
        {
            ii = s.lower_bound( a[ j ] + i );
            if ( ii != s.end( ) )
            {
                ans++;
                s.erase( ii );
            }
        }
    }
    printf("%d\n", ans);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
